require "nvm"

-- 初始化nvm获取配置参数
nvm.init("config.lua", true)
local limitChangeFlag = false

local blueLimit, yellowLimit, orangeLimit, redLimit = tonumber(nvm.get(
                                                                   "blueLimit")),
                                                      tonumber(
                                                          nvm.get("yellowLimit")),
                                                      tonumber(
                                                          nvm.get("orangeLimit")),
                                                      tonumber(
                                                          nvm.get("redLimit"))
local function colorLimitchange()
    if blueLimit < yellowLimit and yellowLimit < orangeLimit and orangeLimit <
        redLimit then
        if blueLimit <= 0 or blueLimit == nil or blueLimit == "" then
            nvm.set("blueLimit", "1")
            limitChangeFlag = true
        end
        if yellowLimit <= 0 or yellowLimit == nil or yellowLimit == "" then
            nvm.set("yellowLimit", "3")
            limitChangeFlag = true
        end
        if orangeLimit <= 0 or orangeLimit == nil or orangeLimit == "" then
            nvm.set("orangeLimit", "5")
            limitChangeFlag = true
        end
        if redLimit <= 0 or redLimit == nil or redLimit == "" then
            nvm.set("redLimit", "7")
            limitChangeFlag = true
        end
    else
        nvm.set("blueLimit", "1")
        nvm.set("yellowLimit", "3")
        nvm.set("orangeLimit", "5")
        nvm.set("redLimit", "7")
        limitChangeFlag = true
    end

    if limitChangeFlag then
        sys.restart("颜色下限值改为默认，重启生效！")
    end
end
sys.taskInit(colorLimitchange)
